<?php
$inc_path = "../";
$li = 1;
require($inc_path."global.php");
uses("trade","industry","company","area","member", "offer");
$member = new Members();
require(INC_PATH .'xajax/xajax.inc.php');
require($inc_path.APP_NAME.'include/page.php');
$xajax = new xajax();
$area = new Areas();
$offer = new Offers();
$company = new Companies();
$industry = new Industries();
$trade = new Trades();
$trade_type = $trade->getTradeTypeKeys("buy");
$tpl_file = "list";
$conditions = null;
$positions = array();
if (!empty($_GET['sid'])) {
	$sid = intval($_GET['sid']);
	$conditions = " and Trade.industry_id=".$sid;
	$tmp_name = $industry->find($sid,"name");

	$positions[4] = $tmp_name;
	$_titles[] = $tmp_name;
}
$positions[2] = "<a href='".URL."buy/' title=''>".$nav[1]['cname']."</a>";
if (isset($_GET['filter'])) {
	$type_id = array_search($_GET['filter'], $trade->buy_types);
	$conditions.= " and Trade.type_id='".intval($type_id)."'";
	$positions[3] = "<a href='#' title=''>".urldecode($_GET['filter'])."</a>";
	$_titles[] = urldecode($_GET['filter']);
}
if (isset($_GET['type'])) {
	if($_GET['type']=="urgent"){
		$conditions.=" and Trade.if_urgent='1'";
		$_titles[] = "紧急采购信息";
	}
}
if (!empty($_GET['companytype'])) {
    uses("companytype");
    $companytype =  new Companytypes();
	$conditions.= " and Company.type_id=".intval($_GET['companytype']);
	$_titles[] = $companytype->field("name", "id=".intval($_GET['companytype']))."企业发布的求购信息";
	$joins['Company']=array("fullTableName"=>$company->getTable(true),"foreignKey"=>"company_id","conditions"=>"Company.type_id=".intval($_GET['companytype']));
}
if (!empty($_GET['search_list'])) {
	if($_GET['provinceid']) $conditions.= " and Trade.province_id=".$_GET['provinceid'];
	if($_GET['cityid']) $conditions.= " and Trade.city_id=".$_GET['cityid'];
	if($_GET['aindustry']) $conditions.= " and Trade.industry_id=".$_GET['aindustry'];
//	if($_GET['keyword']) $conditions.= " and Trade.topic like '%".strip_tags(trim($_GET['keyword']))."%'";
}
if(!empty($sid)){
	$subs = $industry->getAllIndustry("and ParentID=".$sid);
}else{
	$subs = null;
}
$xajax->registerfunction("nextIndustry");
$xajax->registerfunction("loadDivSubIndustry");
//require($inc_path.APP_NAME."include/ajax.inc.php");
setvar("subindustry",$industry->formatSubIndusty($subs));

$conditions.= " and Trade.status=1 and Trade.type_id in ".$trade_type."";
$tables = $trade->getTable(true);
if (isset($_GET['skeyword'])) {
	$searchkeywords = uaAddSlashes($_GET['skeyword']);
	$conditions.= " and Trade.topic like '%".$searchkeywords."%'";
	setvar("searchwords","<font color=\"red\">".$searchkeywords."</font>");
}
$ListAmount = $trade->findCount(" 1 ".$conditions);
pageft($ListAmount,10);
$joins["Member"] =array("fullTableName"=>$member->getTable(true),"foreignKey"=>"member_id","fields"=>"Member.user_type as Membertype,Member.username as MemberUsername");
$joins["Offer"] =array("fullTableName"=>$offer->getTable(true),"foreignKey"=>"id","PrimaryKey"=>"trade_id","fields"=>"prim_im,prim_imaccount,Offer.company_name as OfferCompanyName,prim_tel as PrimTel");
setvar("Lists",$trade->findAll($trade->mini_trade_cols," 1 ".$conditions,"Trade.id desc",$firstcount,$displaypg));
setvar("CurrentPosition", setPosition());
if(empty($_titles)) $_titles[] = "Buyer";
if(isset($_GET['page'])) $_titles[] = $_GET['page'];
setvar("pageTitle", UaController::setTitle($_titles));

uaAssign(array("ByPages"=>$pagenav,"Li"=>$li));
template($theme_name."/trade_".$tpl_file);
?>